﻿//------------------------------------------------------------------------------
// System Name:    Customer Service Platform
// Component:      LogInfoCommon
// Created By:     Samara Jiang (samaraj@wicresoft.com)
// Created Date:   2011-2-27
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASBCC.Business;

namespace ASB.CC.Web.Admin
{
    public partial class LogInfoCommon : EntityPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetModuleName() == null)
                throw new ApplicationException("QueryString['sys']不能为空");

            if (!Enum.GetNames(typeof(SystemModule)).Contains(GetModuleName()))
                throw new ApplicationException("QueryString['sys']格式不正确");
        }

        protected string GetModuleName()
        {
            return this.Request.QueryString["sys"];
        }

        protected string GetRoleStyle(object dataItem)
        {
            return (bool)dataItem ? "role-admin" : "";
        }

        protected override EntityDataSource EntitySource
        {
            get { return edsLog; }
        }

        protected override GridView EntityGrid
        {
            get { return gvLog; }
        }

        protected override DetailsView EntityDetails
        {
            get { return dvLog; }
        }

        protected override TextBox EntitySearchTxt
        {
            get { return txtSearch; }
        }

        protected override Button EntityAddBtn
        {
            get { return btnAdd; }
        }

        protected override Button EntityClearBtn
        {
            get { return btnClear; }
        }

        protected override Button EntitySearchBtn
        {
            get { return btnSearch; }
        }

        protected override void OnEntityDisabling(int entityKey)
        {
            // do nothing
        }

        protected override void OnEntityInserting(EntityDataSourceChangingEventArgs e)
        {
            // do nothing
        }

        protected override void OnEntityUpdating(EntityDataSourceChangingEventArgs e)
        {
            // do nothing
        }
        protected override Panel GridPanel
        {
            get
            {
                return gridPanel;
            }
        }
        protected override string GetEntityWhereExpression(string keyword)
        {
            string startTime = this.Request.Form["Log_StartTime"];
            string endTime = this.Request.Form["Log_EndTime"];
            
            if (!String.IsNullOrEmpty(startTime) && !String.IsNullOrEmpty(endTime))
            {
                DateTime startDate = Convert.ToDateTime(startTime);
                DateTime endDate = Convert.ToDateTime(endTime);
                string time = "it.Time >= cast('" + startDate + "' as System.DateTime)" + " and it.Time <= cast('" + endDate + "' as System.DateTime)";

                return time + "and (it.Description like N'%" + keyword + "%'"
                      + " or it.Module like N'%" + keyword + "%')";
            }
            else
            {

                return "(it.Description like N'%" + keyword + "%'"
                      + " or it.Module like N'%" + keyword + "%')";
            }
        }

    }
}
